package com.upup.cloud.chhk;

import com.upup.cloud.chhk.service.ReptileService;
import com.upup.cloud.chhk.utils.Statics;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Sink;

import javax.annotation.Resource;


@EnableBinding(Sink.class)
@Slf4j
@SpringBootApplication
public class ChhkApplication implements CommandLineRunner {

    @Resource(name = "chReptileServiceImpl")
    ReptileService reptileService;

    public static void main(String[] args) {
        new SpringApplicationBuilder(ChhkApplication.class)
                .web(WebApplicationType.NONE)
                .run(args);
    }

    @Override
    public void run(String... args) throws Exception {

        for (int i = 0; i < 200; i++) {
            new Thread("爬虫线程"+i) {
                @Override
                public void run() {
                    log.info("开启"+this.getName());
                    while (true) {
                        try {
                            reptileService.getFlight();

                        }catch (Exception e){
                            log.info("抓取失败");
                        }
                    }
                }
            }.start();
        }
    }
}

